<template>
  <div class="mod-config  editViewContainer">
    <split-pane class="splitPane" :min-percent='10' :default-percent='10' split="vertical">
      <template slot="paneL">
        <div class="treeViewContainer">
          <tree-view ref="treeView" :treeData="productDeviceTreeList" :checkChangedHandler="getDataList"></tree-view>
        </div>
      </template>
      <template slot="paneR">
        <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :saveAuthName="saveAuthName"
                :deleteAuthName="deleteAuthName"
                :deleteCheckFunc="deleteCheckFunc"
                :optionWidth="200"
                :showAttrs="showAttrs"
                :sumInfo='sumInfo'
                :multiAdd='true'
    >
      <template v-slot:foot="{scope}">
<!--        <el-tooltip style="display: inline-flex; margin-left: 10px;" class="item" effect="dark" content="上传合同"-->
<!--                    placement="bottom"-->
<!--                    :hide-after="1800" :open-delay="800">-->
<!--          <el-upload :action="contractUploadPath" :show-file-list="false">-->
<!--            <el-button type="warning" icon="el-icon-upload2" size="small"></el-button>-->
<!--          </el-upload>-->
<!--        </el-tooltip>-->
        <el-tooltip class="item" effect="dark" content="查看订单详情" placement="bottom" :hide-after="1800" :open-delay="800">
          <el-button size="small" type="text" @click="showOrderDetail(R.path(['row', primaryKey], scope))">
            详情
          </el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="修改合同订单信息" placement="bottom" :hide-after="1800" :open-delay="800">
          <el-button size="small" type="text" @click="updateContractOrderDialog(R.path(['row', primaryKey], scope))">
             变更
          </el-button>
        </el-tooltip>
<!--        <el-tooltip class="item" effect="dark" content="导出订单合同" placement="bottom" :hide-after="1800" :open-delay="800">-->
<!--          <el-button type="text" size="small" @click="exportOrderContract(R.path(['row', primaryKey], scope))">订单合同-->
<!--          </el-button>-->
<!--        </el-tooltip>-->

      </template>

    </table-view>
      </template>
    </split-pane>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <order-add-or-update v-if="orderVisible" ref="order"></order-add-or-update>
    <client-info-add-or-update v-if="clientInfoVisible" ref="clientInfo"></client-info-add-or-update>
    <product-info-add-or-update v-if="productInfoVisible" ref="productInfo"></product-info-add-or-update>
    <model-info-add-or-update v-if="modelInfoVisible" ref="modelInfo"></model-info-add-or-update>
    <sys-dict-add-or-update v-if="sysDictVisible" ref="sysDict"></sys-dict-add-or-update>

    <order-update v-if="orderUpdateVisible" ref="orderInfoUpdate"></order-update>

    <order-model-add-or-update v-if="orderModelVisible" ref="orderModelInfo"></order-model-add-or-update>

    <commodity-info-add-or-update-order v-if="commodityInfoVisible" ref="commodityInfo"></commodity-info-add-or-update-order>

    <bottle-cap-info-add-or-update v-if="bottleCapInfoVisible" ref="relateBottleCapInfo"></bottle-cap-info-add-or-update>
    <center-cover-info-add-or-update v-if="centerCoverInfoVisible" ref="relateCenterCoverInfo"></center-cover-info-add-or-update>
    <neck-ring-info-add-or-update v-if="neckRingInfoVisible" ref="relateNeckRingInfo"></neck-ring-info-add-or-update>
    <spray-head-info-add-or-update v-if="sprayHeadInfoVisible" ref="relateSprayHeadInfo"></spray-head-info-add-or-update>



    <el-dialog title="订单详情" :visible.sync="orderDialog" v-loading="orderLoading" width="70%">
      <el-table :data="orderDataList" border style="width: 100%;">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column prop="productNo" header-align="center" align="center" label="产品编号"></el-table-column>
        <el-table-column prop="orderProductNumber" header-align="center" align="center" label="订单数量"></el-table-column>
        <el-table-column prop="unitPrice" header-align="center" align="center" label="单价"></el-table-column>
        <el-table-column prop="productWeight" header-align="center" align="center" label="克数"></el-table-column>
        <el-table-column prop="productVolume" header-align="center" align="center" label="容量"></el-table-column>
        <el-table-column prop="status" header-align="center" align="center" label="状态">
          <template slot-scope="scope">
            <template v-for="item in orderStatusList">
              <el-tag v-if="R.equals(item.value,scope.row.status)"
                      size="small"
                      :type="item.tagType"
                      :Key="item.value"
              >{{ item.text }}
              </el-tag>
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="putInStorageValue" header-align="center" align="center" label="入库数量"></el-table-column>
        <el-table-column prop="leaveStorageValue" header-align="center" align="center" label="出库数量"></el-table-column>
        <el-table-column prop="inventory" header-align="center" align="center" label="剩余数量"></el-table-column>
        <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="修改订单" placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button size="small" type="text" @click="updateOrderDetail(scope.row,scope.row.id)">
                变更
              </el-button>
            </el-tooltip>

<!--            <el-tooltip class="item" effect="dark" content="发货" placement="bottom" :hide-after="1800" :open-delay="800">-->
<!--              <el-button type="danger" size="small" icon="el-icon-truck" @click="deliveryOrderDetail(scope.row.id)"></el-button>-->
<!--            </el-tooltip>-->

          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="orderDialog = false;getDataList()">取 消</el-button>
        <el-button type="primary" @click="orderDialog = false;getDataList()">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="批量修改订单"
      :visible.sync="contractOrderVisible"
      width="90%">

      <el-form
        ref="dataForm"
        label-width="120px"
        label-position="left"
        :model="contractOrderInfo"
        style="margin-left:30px;"
      >
        <el-row>
          <el-col :span="12" >
            <el-form-item label="客户" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.clientName"
                         style="width:90%"
                         placeholder="客户"></el-input>
            </el-form-item>
            <el-form-item label="客户类型" style="margin-bottom: 10px">

              <el-select v-model="contractOrderInfo.clientType"   placeholder="客户类型">
                <el-option
                  v-for="item in clientTypeList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>

            </el-form-item>

            <el-form-item label="订单状态" style="margin-bottom: 10px">
              <el-radio-group size="small" v-model="contractOrderInfo.orderStatus" @change="changeOrderStatusFun">
                <el-radio :label=-1 >缺货</el-radio>
                <el-radio :label=0 >配货中</el-radio>
                <el-radio :label=50 >部分发货</el-radio>
                <el-radio :label=55 >已全发货</el-radio>
                <el-radio :label=95 >客户退款</el-radio>
                <el-radio :label=99 >客户取消</el-radio>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="运费" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.freight"
                         style="width:90%"
                         placeholder="运费"></el-input>
            </el-form-item>


            <el-form-item label="合计总价" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.totalAmount"
                         style="width:90%"
                         placeholder="合计总价"></el-input>
            </el-form-item>
            <el-form-item label="付款账户" style="margin-bottom: 10px;width: 90%" >
              <el-select v-model="contractOrderInfo.vouchAccount"   placeholder="付款账户">
                <el-option
                  v-for="item in vouchAccountList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="已付金额" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.paidAmount"
                         style="width:90%"
                         placeholder="已付金额"></el-input>
            </el-form-item>
            <el-form-item label="支付尾款" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.finalPaymentAmount"
                         style="width:90%"
                         placeholder="支付尾款"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" >

            <el-form-item label="订单编号-1688" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.contractNo"
                         placeholder="订单编号-1688"></el-input>
            </el-form-item>
            <el-form-item label="订单时间" style="margin-bottom: 10px">
              <el-date-picker
                v-model="contractOrderInfo.contractTime"
                align="left"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="数量合计" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.realSaleNumber"
                         placeholder="数量合计"></el-input>
            </el-form-item>

<!--            vouchAccount-->
            <el-form-item label="付款方式" style="margin-bottom: 10px">
              <el-radio-group size="small" v-model="contractOrderInfo.paymentWay">
                <el-radio :label=0 >已付全款</el-radio>
                <el-radio :label=1 >已付定金</el-radio>
                <el-radio :label=2 >付尾款</el-radio>
                <el-radio :label=90 >未付款</el-radio>
              </el-radio-group>

<!--              <el-input  size="small" v-model="contractOrderInfo.paymentWay"
                         placeholder="付款方式"></el-input>-->
            </el-form-item>
            <el-form-item label="优惠金额" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.discountPrice"
                         placeholder="优惠金额"></el-input>
            </el-form-item>
            <el-form-item label="付款金额" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.paymentTotalAmount"
                         placeholder="付款金额"></el-input>
            </el-form-item>
            <el-form-item label="预发货时间" style="margin-bottom: 10px">
              <el-date-picker
                v-model="contractOrderInfo.deliveryTime"
                align="left"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item v-if="contractOrderInfo.orderStatus==50||contractOrderInfo.orderStatus==55" label="物流单号" style="margin-bottom: 10px">
              <el-input  size="small" v-model="contractOrderInfo.trackingNo"
                         style="width:90%"
                         placeholder="物流单号"></el-input>
            </el-form-item>
            <el-form-item label="备注" style="margin-bottom: 10px" >
              <el-input  size="small" v-model="contractOrderInfo.remark"
                         placeholder="备注"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

<!--        <el-form-item label="生产线" style="width: 400px">-->
<!--          <el-select v-model="deviceId" clearable filterable @change="changeProductDeviceId(deviceId)"-->
<!--                     placeholder="请选择">-->
<!--            <el-option-->
<!--              v-for="item in productDeviceList"-->
<!--              :key="item.id"-->
<!--              :label="item.name"-->
<!--              :value="item.id">-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->

<!--        <el-form-item label="上机时间" style="width: 400px">-->
<!--          <el-date-picker-->
<!--            v-model="onlineTime"-->
<!--            align="right"-->
<!--            type="date"-->
<!--            placeholder="选择日期"-->
<!--            value-format="yyyy-MM-dd HH:mm:ss"-->
<!--          >-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->


      </el-form>

      <el-table
        :data="contractOrderInfo.tableListData"
        border
        style="display: inline-block">

        <el-table-column
          prop="productId"
          label="产品名称"
          align="center"
        >
          <template slot-scope="scope">
            <el-select v-model="scope.row.productId"  placeholder="请选择">
              <el-option
                v-for="item in productInfoList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </template>
        </el-table-column>

        <el-table-column
          prop="orderProductNumber"
          label="数量"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0"
                             v-model="scope.row.orderProductNumber"
                             placeholder="数量"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column
          prop="unitPrice"
          label="单价"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0" v-model="scope.row.unitPrice"
                             placeholder="单价"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column
          prop="totalPrice"
          label="总价"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0" v-model="scope.row.totalPrice"
                             placeholder="总价"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="productWeight"
          label="克重"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0" v-model="scope.row.productWeight"
                             placeholder="克重"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          width="130"
          align="center"
        >
          <template slot-scope="scope">
            <el-select v-model="scope.row.status" clearable filterable placeholder="状态">
              <el-option label="配货中" :value=0>配货中</el-option>
              <el-option label="缺货" :value=-1>缺货</el-option>
              <el-option label="部分发货" :value=50>部分发货</el-option>
              <el-option label="已全发货" :value=55>已全发货</el-option>
              <el-option label="客户退款" :value=95>客户退款</el-option>
              <el-option label="客户取消" :value=99>客户取消</el-option>
            </el-select>
          </template>
        </el-table-column>


<!--        <el-table-column-->
<!--          prop="specialMark"-->
<!--          label="箱唛"-->
<!--          align="center"-->
<!--          width="110"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <el-select v-model="scope.row.specialMark" clearable filterable placeholder="箱唛">-->
<!--              <el-option label="普英唛" :value=0>普英唛</el-option>-->
<!--              <el-option label="专用唛" :value=1>专用唛</el-option>-->
<!--              <el-option label="普英唛+H" :value=2>普英唛+H</el-option>-->
<!--            </el-select>-->
<!--          </template>-->
<!--        </el-table-column>-->



<!--        <el-table-column-->
<!--          prop="groupNumber"-->
<!--          label="模具组数"-->
<!--          width="100"-->
<!--          align="center"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <el-input-number controls-position="right" size="small" :min="0" v-model="scope.row.groupNumber"-->
<!--                             placeholder="模具组数"></el-input-number>-->
<!--          </template>-->
<!--        </el-table-column>-->

<!--        <el-table-column-->
<!--          prop="bottleOutDiameter"-->
<!--          label="口径"-->
<!--          align="center"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <el-input size="small" v-model="scope.row.bottleOutDiameter" placeholder="口径"></el-input>-->
<!--          </template>-->
<!--        </el-table-column>-->



        <el-table-column
          prop="remark"
          label="备注"
          align="center"
        >
          <template slot-scope="scope">
            <el-input type="textarea" controls-position="right" size="small" :min="0" v-model="scope.row.remark"
                      placeholder="备注"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="130px"
        >
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="addRow(scope.$index, contractOrderInfo.tableListData)"
              type="success"
              icon="el-icon-plus"
              circle>
            </el-button>
            <el-button v-if="scope.row.id==''"
                       @click.native.prevent="deleteRow(scope.$index, contractOrderInfo.tableListData)"
                       icon="el-icon-delete"
                       type="danger"
                       circle>
            </el-button>
          </template>
        </el-table-column>
      </el-table>


      <span slot="footer" class="dialog-footer">
        <el-button @click="contractOrderVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateContactOrderListInfo">确 定</el-button>
      </span>

    </el-dialog>
  </div>
</template>


<script>
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
// import AddOrUpdate from './contractorderinfo-add-or-update'
import AddOrUpdate from './online-order-info-add-or-update-3.vue'
import ProductInfoAddOrUpdate from '@/views/modules/product/productinfo-add-or-update'
import OrderAddOrUpdate from '@/views/modules/order/orderdetail-add-or-update'
import OrderUpdate from '@/views/modules/order/orderdetail-update'
import ClientInfoAddOrUpdate from '@/views/modules/client/clientinfo-add-or-update'
import ModelInfoAddOrUpdate from '@/views/modules/model/modelinfo-add-or-update'
import {exportHandle} from '@/utils'
import {mRequest} from '@/utils/request'
import SysDictAddOrUpdate from '@/views/modules/sys/sysdict-add-or-update'
import OrderModelAddOrUpdate from '@/views/modules/order/ordermodel-add-or-update'
import CommodityInfoAddOrUpdateOrder from '@/views/modules/commodity/commodityinfo-add-or-update-order'
import BottleCapInfoAddOrUpdate from '@/views/modules/relate/relatebottlecapinfo-add-or-update.vue'
import CenterCoverInfoAddOrUpdate from '@/views/modules/relate/relatecentercoverinfo-add-or-update.vue'
import NeckRingInfoAddOrUpdate from '@/views/modules/relate/relateneckringinfo-add-or-update.vue'
import SprayHeadInfoAddOrUpdate from '@/views/modules/relate/relatesprayheadinfo-add-or-update.vue'
import treeView from '@/components/treeView'

export default {
  mixins: [basicMixins],
  data() {
    return {
      contractOrderInfo: {
        id: '',
        contractType: '',
        clientName: '',
        contractNo: '',
        clientType: '',
        contractTime: '',
        vouchAccount: '',
        realSaleNumber: '',
        freight: '',
        discountPrice: '',
        totalAmount: '',
        paymentWay: '',
        paymentTotalAmount: '',
        remark: '',
        paidAmount: 0,
        finalPaymentAmount: 10,
      },
      clientTypeList: [],
      productDeviceTreeList: [],
      productDeviceList: [],
      tableListData: [],
      orderDataList: [],
      productInfoList: [],
      vouchAccountList: [],
      orderLoading: false,
      orderDialog: false,
      orderVisible: false,
      sysDictVisible: false,
      orderUpdateVisible: false,
      commodityInfoVisible: false,
      contractOrderVisible: false,
      orderStatusList: [
        {value: -1, text: '缺货', tagType: 'danger'},
        {value: 0, text: '待配货',tagType: 'info'},
        {value: 15, text: '采购中', tagType: 'warning'},
        {value: 17, text: '采购完成', tagType: 'success'},
        {value: 20, text: '未出货', tagType: 'primary'},
        {text: '部分发货',value: 50,},
        {text: '已全出货',value: 55 },
        {value: 66, text: '已签收', tagType: 'success'},
        {value: 90, text: '客户退货', tagType: 'danger'},
        {value: 99, text: '订单取消', tagType: 'danger'}
      ],
      clientInfoVisible: false,
      productInfoVisible: false,
      modelInfoVisible: false,
      orderModelVisible: false,
      bottleCapInfoVisible: false,
      centerCoverInfoVisible: false,
      neckRingInfoVisible: false,
      sprayHeadInfoVisible: false,
      sumInfo: {realSaleNumber: 'realSaleNumber',totalAmount:'totalAmount',freight:'freight'},

      //  contractUploadPath: 'https://jsonplaceholder.typicode.com/posts/',
      primaryKey: 'id',
      listApiName: 'contractApi/listContractOrderInfoList',
      deleteApiName: 'contractApi/deleteContractOrderInfo',
      saveAuthName: 'contract:contractorderinfo:save',
      deleteAuthName: 'contract:contractorderinfo:delete',
      searchAttrs: {
        productNo: {
          label: '产品名称',
          placeholder: '请输入产品名称'
        },
        orderStatus: {
          label: '订单状态',
          placeholder: '请输入订单状态'
        },
        clientName: {
          label: '客户名称',
          clearable: true,
          placeholder: '请输入客户名称'
        },
        paymentWay:{
          label: '付款状态',
          placeholder: '请输入付款状态',
          clearable: true,
          type: 'list',
          list: []
        },
        // createUser: {
        //   label: '销售',
        //   clearable: true,
        //   type: 'autoComplete',
        //   placeholder: '请选择销售人员',
        //   querySearchApiName: 'systemApi/listSaleUser'
        //
        // },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        },
        clientType: {
          type: 'func',
          dataFunc: () => {
            return this.$refs.treeView.$refs.treeForm.getCheckedKeys()[0]
          }
        },
      },
      showAttrs: {
        contractNo: {
          label: '订单编号',
          width: 150
        },
        clientName: {
          label: '客户',
          width: 120
        },
        contractTime: {
          label: '订单日期',
          type: 'date',
          width: 95
        },
        commodityName: {
          label: '货号规格',
          width: 170
        },
        realSaleNumber:{
          label: '商品总量',
        },


        freight:{
          label: '运费'
        },
        totalAmount: {
          label: '总金额'
        },
        orderStatus: {
          label: '订单状态',
          type: 'radio',
          width: 120,
          items: [
            {value: -1, text: '缺货',tagType: 'danger'},
            {value: 0, text: '配货中',tagType: 'info'},
            {value: 50, text: '已部发货',tagType: 'warning'},
            {value: 55, text: '已全发货',tagType: 'success'},
            {value: 95, text: '客户取消',tagType: 'danger'},
            {value: 99, text: '客户取消',tagType: 'danger'}
          ]
        },
        paymentWay:{
          label: '付款方式',
          type: 'radio',
          items: [
            {value: 0, text: '已付全款',tagType: 'success'},
            {value: 1, text: '已付定金'},
            {value: 90, text: '未付款',tagType: 'danger'},
          ],
        },
        vouchAccount: {
          label: '收款账户',
          type: 'radio',
          items: [
            {text: '店支付宝', value: 1},
            {text: '店微信', value: 2},
            {text: '位支付宝', value: 3},
            {text: '位微信', value: 4},
            {text: '杜支付宝', value: 5},
            {text: '杜微信', value: 6},
            {text: '兴玻公户', value: 7},
            {text: '农行51570', value: 8},
            {text: '农商行4602', value: 9},
            {text: '建行1085', value: 10},
            {text: '中国银行8758', value: 11},
            {text: '鸿源公户', value: 12},
            {text: '未付款', value: 90}
          ]
        },
        deliveryTime: {label: '交付日期', type: 'date', width: 95},


        salesPerson: {
          label: '销售人员'
        },
        trackingNo: {
          label: '物流单号'
        },

        // transportWay: {
        //   label: '运输方式',
        //   type: 'radio',
        //   items: [
        //     {value: 0, text: '快递'},
        //     {value: 1, text: '需方自提',tagType:'danger'}
        //   ]
        // },
        remark: {
          label: '备注'
        },
        discountPrice:{
          label: '优惠金额'
        },
        contractStatus: {
          label: '合同状态',
          type: 'radio',
          items: [
            {value: 3, text: '客户已确认'},
            {value: 99, text: '合同取消',tagType: 'danger'}
          ]
        },
      },
    }
  },
  mounted() {
    this.productDeviceTreeListInit()
  },
  methods: {
    productDeviceTreeListInit() {
      mRequest('orderApi/getOrderClientTypeList', {}, (res) => {
        this.productDeviceList = this.R.pathOr([], ['data', 'list'], res)
        const productDeviceTreeList = [{
          id: '',
          name: '客户类型',
          nodeType: 0,
          children: []
        }]

        productDeviceTreeList[0].children = this.productDeviceList
        this.productDeviceTreeList = productDeviceTreeList;
      })

      this.searchAttrs['paymentWay'].list = [
        {id: 0, name: '已付全款'},
        {id: 1, name: '已付定金'},
        {id: 2, name: '付尾款'},
        {id: 90, name: '未付款'}
      ]
    },
    updateContractOrderDialog(id) {
      this.contractOrderVisible = true
      this.initProductInfoList()
      this.initFinanceAccountInfoList()
      mRequest('contractApi/contractOrderInfoInfo', {id: id}, (res) => {
        this.contractOrderInfo = this.R.pathOr('', ['data', 'contractOrderInfo'], res)


      })
    },
    updateContactOrderListInfo() {
      this.contractOrderVisible = false
        mRequest('contractApi/updateContractAndOrder', this.contractOrderInfo
        , (data) => {
          if (data.data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500
            })
          } else {
            this.$message.error(data.data.msg)
          }
          this.getDataList()
          this.deepDialogVisible = false
        })
    },
    addRow(index, rows) {
      rows.push({
        id: '',
        productId: '',
        unitPrice: 0,
        totalPrice: 0,
        orderProductNumber: 0,
        productWeight: 0,
        remark: ''
      });
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    openSysDicDialog(cb) {
      this.sysDictVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.sysDict)) {
          this.$refs.sysDict.init(null, {}, cb)
        }
      })
    },

    deleteCheckFunc(deleteItems) {
      if (deleteItems.filter(this.R.propEq('contractStatus', 3)).length > 0) {
        this.$message.error('由于合同状态不是草稿 ， 不允许删除')
        return false
      }
      return true
    },
    openCommodityInfoDialog(cb) {
      this.commodityInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.commodityInfo)) {
          this.$refs.commodityInfo.init(null, {}, cb)
        }
      })
    },
    openBottleCapInfoDialog(cb) {
      this.bottleCapInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.relateBottleCapInfo)) {
          this.$refs.relateBottleCapInfo.init(null, {}, cb)
        }
      })
    },
    openCenterCoverInfoDialog(cb) {
      this.centerCoverInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.relateCenterCoverInfo)) {
          this.$refs.relateCenterCoverInfo.init(null, {}, cb)
        }
      })
    },
    openNeckRingInfoDialog(cb) {
      this.neckRingInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.relateNeckRingInfo)) {
          this.$refs.relateNeckRingInfo.init(null, {}, cb)
        }
      })
    },
    openSprayHeadInfoDialog(cb) {
      this.sprayHeadInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.relateSprayHeadInfo)) {
          this.$refs.relateSprayHeadInfo.init(null, {}, cb)
        }
      })
    },


    openModelInfoDialog(cb) {
      this.modelInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.modelInfo)) {
          this.$refs.modelInfo.init(null, {}, cb)
        }
      })
    },
    openProductInfoDialog(clientId,cb) {
      this.productInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productInfo)) {
          this.$refs.productInfo.init(null, {'clientId':clientId}, cb)
        }
      })
    },
    openProductInfoDialog2(id,cb) {
      this.productInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productInfo)) {
          this.$refs.productInfo.init(id, {}, cb)
        }
      })
    },
    openOrderDialog(param, cb) {
      this.orderVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.order)) {
          this.$refs.order.init(param.id, param, cb, false)
        }
      })
    },
    openClientInfoDialog(cb) {
      this.clientInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.clientInfo)) {
          this.$refs.clientInfo.init(null, {}, cb)
        }
      })
    },
    openOrderModelDialog(property) {
      this.orderModelVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.orderModelInfo)) {
          this.$refs.orderModelInfo.init(null,property)
        }
      })
    },
    exportOrderContract(id) {
      exportHandle('contractApi/getWordOrderContractExport', {contractOrderId: id})
    },
    showOrderDetail(id) {
      this.orderDialog = true
      this.orderLoading = true

      this.$nextTick(() => {
        mRequest('orderApi/getOrderListByContractOrderId', {contractOrderId: id}, (res) => {
          const list = this.R.pathOr([], ['data', 'list'], res)
          this.orderDataList = this.R.map((item) => ({
            id: this.R.propOr(0, 'id', item),
            contractOrderId: this.R.propOr(0, 'contractOrderId', item),
            productNo: this.R.propOr(0, 'productNo', item),
            modelNo: this.R.propOr(0, 'modelNo', item),
            productVolume: this.R.propOr(0, 'productVolume', item) + ' ' + this.R.propOr('', 'volumeScope', item),
            orderProductNumber: this.R.propOr(0, 'orderProductNumber', item),
            productWeight: this.R.propOr(0, 'productWeight', item) + ' ' + this.R.propOr('', 'weightScope', item),
            unitPrice: this.R.propOr(0, 'unitPrice', item),
            status: this.R.propOr(0, 'status', item),
            putInStorageValue: this.R.propOr(0, 'putInStorageValue', item),
            leaveStorageValue: this.R.propOr(0, 'leaveStorageValue', item),
            inventory: this.R.propOr(0, 'putInStorageValue', item) - this.R.propOr(0, 'leaveStorageValue', item)
          }), list)
        })
        this.orderLoading = false
      })
    },
    updateOrderDetail(param){
      this.orderUpdateVisible = true

      this.$nextTick(() => {
        const cb = (newValue) => {
          mRequest('orderApi/getOrderListByContractOrderId', {contractOrderId: newValue.contractOrderId}, (res) => {
            const list = this.R.pathOr([], ['data', 'list'], res)
            this.orderDataList = this.R.map((item) => ({
              id: this.R.propOr(0, 'id', item),
              productNo: this.R.propOr(0, 'productNo', item),
              modelNo: this.R.propOr('', 'modelNo', item),
              productVolume: this.R.propOr(0, 'productVolume', item) + ' ' + this.R.propOr('', 'volumeScope', item),
              orderProductNumber: this.R.propOr(0, 'orderProductNumber', item),
              productWeight: this.R.propOr(0, 'productWeight', item) + ' ' + this.R.propOr('', 'weightScope', item),
              unitPrice: this.R.propOr(0, 'unitPrice', item),
              status: this.R.propOr(0, 'status', item),
              putInStorageValue: this.R.propOr(0, 'putInStorageValue', item),
              leaveStorageValue: this.R.propOr(0, 'leaveStorageValue', item),
              inventory: this.R.propOr(0, 'putInStorageValue', item) - this.R.propOr(0, 'leaveStorageValue', item)
            }), list)
          })
        }
        if (!this.R.isNil(this.$refs.orderInfoUpdate)) {
          this.$refs.orderInfoUpdate.init(param.id, param,cb)
        }
      })
    },
    initProductInfoList() {
      mRequest('productApi/getProductInfoList', {}, (res) => {
        this.productInfoList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initFinanceAccountInfoList() {
      mRequest('financeApi/getFinanceAccountInfoList', {}, (res) => {
        this.vouchAccountList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    changeOrderStatusFun() {
      const orderStatus= this.contractOrderInfo.orderStatus
      this.contractOrderInfo.tableListData.forEach(item => {
        item.status = orderStatus
      })
    },
    deliveryOrderDetail(id){
      console.info('id ' + id)
    }
  },
  components: {
    tableView,
    treeView,
    AddOrUpdate,
    SysDictAddOrUpdate,
    OrderModelAddOrUpdate,
    OrderAddOrUpdate,
    ProductInfoAddOrUpdate,
    ClientInfoAddOrUpdate,
    OrderUpdate,
    CommodityInfoAddOrUpdateOrder,
    BottleCapInfoAddOrUpdate,
    CenterCoverInfoAddOrUpdate,
    NeckRingInfoAddOrUpdate,
    SprayHeadInfoAddOrUpdate,
    ModelInfoAddOrUpdate
  }
}
</script>
